package cando1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 安慕希
 * Date: 2025-03-14
 * Time: 14:29
 */
public class Student {
    public String name = "小林同学";//未完全初始化将会默认“赋值”;(对于成员变量而言)
    public String classRoom;
    public int age = 20;
    public double kiloGram = 54.5;//你可以选择就地初始化

    public Student(){//你也可以选择构造方法初始化
        //构造方法：名字必须与类名相同，在创建对象时，由编译器⾃动调⽤，并且在整个对象的⽣命周期内只调⽤⼀次
        this.age = age;
/*        System.out.println("没有含参数的构造方法被调用了");*/
    }

  /*  public String toString() {
        return "改写方法...";
    }*/

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", classRoom='" + classRoom + '\'' +
                ", age=" + age +
                ", kiloGram=" + kiloGram +
                '}';
    }

    public Student(int age, String classRoom){
        //若方法名相同，参数数量不同，则构造方法也会构成方法重载
        this.age = 15;
        this.classRoom = "初二三班";
    }

    public void Sleep(){
        System.out.println(name+"正在睡觉");
    }
    public void DoHomework(){
        System.out.println(name+"正在做作业");
    }
}
